//@ts-ignore
import { requestHttp } from "@/utils/requestHttp.ts";

//引入类型约束
import { responseCommodityInfoListData } from "./type.ts";
import type { standard } from "./type.ts";

/**
 * 查询商品规格信息--->
 * 查询商品信息(支持分页查询) get请求
 * page=1
 * pageSize=3
 */
export const reqCommodityList = (page:number = 1, pageSize:number = 3) => {
    return requestHttp<responseCommodityInfoListData>({
        url:"/manage/commodity",
        method:"get",
        params:{
            page:page,
            pageSize:pageSize
        }
    })
}

/**
 * 添加一个商品规格信息 post
 * 请求体 = {commodityId:?,commodityAttr:?,commodityPrice:?,commodityStore:?}
 */
export const reqSaveCommodityStandard = (starnardInfo:standard) => {
    return requestHttp({
        url:"/manage/commodity/standard",
        method:"post",
        data:starnardInfo
    })
}

/**
 * 添加一个商品规格信息 post
 * 请求体 = {id:?,commodityAttr:?,commodityPrice:?,commodityStore:?}
 */
 export const reqUpdateCommodityStandard = (starnardInfo:standard) => {
    return requestHttp({
        url:"/manage/commodity/standard",
        method:"put",
        data:starnardInfo
    })
}

/**
 * 删除一个商品规格信息 delete
 * queryParams  standardId = ?
 */
 export const reqDeleteCommodityStandard = (standardId:number) => {
    return requestHttp({
        url:"/manage/commodity/standard",
        method:"delete",
        params:{
            standardId:standardId
        }
    })
}

/**
 * 搜索商品名称查询商品及其规格信息***
 * 根据商品名称对商品进行模糊搜索api
 * get  commodityName = ?
 */
 export const reqCommodityListByCommodityNmae = (commodityName:string) => {
    return requestHttp<responseCommodityInfoListData>({
        url:"/manage/commodity/like",
        method:"get",
        params:{
            commodityName:commodityName
        }
    })
}